package com.nexttwist.adapters;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.nexttwist.R;
import com.nexttwist.model.Comment;

public class CommentsAdapter extends ArrayAdapter<Comment>  {
	
	private final Context context;
	private final List<Comment> data;

	public CommentsAdapter(Context context, List<Comment> objects) {
		super(context, R.layout.comment_list_item, objects);
		this.context = context;
		this.data = objects;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		//return super.getView(position, convertView, parent);
		LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View rowView = mInflater.inflate(R.layout.comment_list_item, parent, false);
		final ImageButton mBtnDelete = (ImageButton) rowView.findViewById(R.id.btn_delete);
		ImageView mProfilePitcture = (ImageView) rowView.findViewById(R.id.profile_picture);
		TextView mComments = (TextView) rowView.findViewById(R.id.album_title);
		
		Comment comment = data.get(position);
		
		mComments.setText(comment.getComment());
		
		final int fPosition = position;
		mBtnDelete.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Comment commentObj = data.get(fPosition);
				Toast.makeText(context, "comment clicked", Toast.LENGTH_LONG).show();
				//	MyMediaPlayer.getInstance().play(commentObj.getTrackId());

			}
		});
		
		return rowView;
	}
}
